<div class="pageheader">
	<h2>
		<i class="fa fa-users"></i>用户管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>用户管理</li>
			<li class="active">用户列表</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
<div class="main">
    <ol class="breadcrumb">
        <li><a href="#">用户管理</a></li>
       <li><a href="#">用户列表</a></li>
    </ol>
    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>用户名</th>
                    <th>真实姓名</th>
                    <th>QA邮箱</th>
                    <th>用户类型</th>
                    <th>团队管理者</th>
                    <th>权限</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>      
                <?php if ($this->userList):?>
	            <?php foreach ($this->userList as $v):?>                       
		        <tr>
		            <td><?php echo $v->user_name;?></td>
		            <td><?php echo $v->true_name;?></td>
		            <td><?php echo $v->email;?></td>
		            <td>
		                <?php
		                if($v->user_type == 0){
		                	echo '未选择';
		                }else if($v->user_type == 1){
		                	echo '管理团队';
		                }else if($v->user_type == 2){
		                	echo '运营团队';
		                }else if($v->user_type == 3){
		                	echo '技术团队';
		                }else if($v->user_type == 4){
		                	echo '仓储行政团队';
		                }
		                ?>
		            </td>
		            <td><?php echo $v->is_admin == 1 ? '是' : '否';?></td>		
		            <td>
		                <?php
		                $p = json_decode($v->permission);
		                if(in_array('1', $p)){
		                	echo '库存管理;';
		                }
		                if(in_array('2', $p)){
		                	echo '日志管理;';
		                }
		                if(in_array('3', $p)){
		                	echo '销售管理;';
		                }
		                if(in_array('4', $p)){
		                	echo '客户管理;';
		                }
		                if(in_array('5', $p)){
		                	echo '办公管理;';
		                }
		                if(in_array('6', $p)){
		                	echo '用户管理;';
		                }
		                ?>
		            </td>	                   
				    <td>
				        <?php if($_SESSION['User']['user']['is_admin']==1):?>
				        <a class="btn btn-default btn-sm" title="删除" href="javascript:void(0);" onclick="deleteUser(<?php echo $v->user_id; ?>, this)">删除</a>
				        <?php endif;?> 
				        <a class="btn btn-default btn-sm" title="修改" href="<?php echo $this->url(array('controller'=>'auth','action'=>'update','id'=>$v->user_id),null,true)?>">修改</a>
				    </td>   
		        </tr>
		        <?php endforeach;?>
		        <?php endif;?>	
		    </tbody>
        </table>
    </div>
</div>
</div>

<script type="text/javascript">
function deleteUser(id, obj) {
    if (confirm('确认删除?')) {
	    $.ajax({
		    type: "get",
		    url: "/auth/delete?id="+id,
		    data: {},
		    success: function(data) {
			    switch(data) {
			    case "1":
				    alert('删除成功');
				    $(obj).parent().parent().remove();
				    break;
				default:
					alert('删除失败');
	            }
	         }			
        });
    }
}
</script>